/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**递归法
 * 1. 确定递归函数的返回值 参数
 * 2. 确定递归函数的终止条件
 * @param {TreeNode} root
 * @param {TreeNode} subRoot
 * @return {boolean}
 */

 const tools = (root,subRoot) => {
    if(root==null&&subRoot==null) return true
    else if(root!=null&&subRoot==null) return false
    else if(root==null&&subRoot!=null) return false
    else if(root.val!==subRoot.val) return false
    let left = tools(root.left,subRoot.left)
    let right = tools(root.right,subRoot.right)
    return left&&right
}
 var isSubtree = function(root, subRoot) {
    let queue = [root]
    while(queue.length){
        let curr = queue.shift()
        if(tools(curr,subRoot)){
            return true
        }else{
            curr.left&&queue.push(curr.left)
            curr.right&&queue.push(curr.right)
        }
    }
    return false
};